package com.jk.bglog.service;

import com.jk.bglog.dao.OrderDao;
import com.jk.bglog.entity.OrderLogEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderService {
    @Resource
    private OrderDao dao;
    @Autowired
    private MongoTemplate MongoTemplate ;


    public void addOrder(OrderLogEntity orderLogEntity) {

        MongoTemplate.save(orderLogEntity);
    }

    public List<OrderLogEntity> queryOrderList(OrderLogEntity orderLogEntity) {
        Query query = new Query();
        if (orderLogEntity.getOrderNum()!=null && orderLogEntity.getOrderNum() != ""){
            query.addCriteria(Criteria.where("orderNum").is(orderLogEntity.getOrderNum()));
        }
        if (StringUtils.isNotBlank(orderLogEntity.getOrderStartTime()) && StringUtils.isNotBlank(orderLogEntity.getOrderEndTime())){
            query.addCriteria(Criteria.where("orderDate").lte(orderLogEntity.getOrderEndTime()).gte(orderLogEntity.getOrderStartTime()));
        }
        if (orderLogEntity.getOrderCondition()!=null){
            query.addCriteria(Criteria.where("orderCondition").is(orderLogEntity.getOrderCondition()));
        }
        List<OrderLogEntity> orderLogEntities = MongoTemplate.find(query, OrderLogEntity.class);
        return orderLogEntities;


    }




}
